package com.chen.controller;

import com.chen.service.IAccount;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@Slf4j
@RestController
@RequestMapping("/accountB")
@Api(value = "微服务2-模拟银行2",tags = "账户管理")
public class AccountController {
    @Autowired
    private IAccount accountService;

    /**
     * 向账户转入资金
     * @param accountId 转入账户
     * @param amount    转入资金
     */
    @PostMapping("/transferInto")
    @ApiOperation(value = "向指定账户转入资金，账户不存在则抛出异常")
    public void transferInto(@RequestParam("accountId") int accountId,@RequestParam("amount") BigDecimal amount) throws Exception {
        log.info("执行/accountB/transferInto");
        accountService.transferInto(accountId,amount);
    }


    /**
     * 向账户转入资金
     * @param accountId 转入账户
     * @param amount    转入资金
     */
    @PostMapping("/transferIntoWithException")
    @ApiOperation(value = "向指定账户转入资金，账户不存在则抛出异常,模拟转入账户出现异常")
    public void transferIntoWithException(@RequestParam("accountId") int accountId,@RequestParam("amount") BigDecimal amount) throws Exception {
        log.info("执行/accountB/transferIntoWithException");
        accountService.transferIntoWithException(accountId,amount);
    }



}
